package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.Cost;

public class CostPresenter extends AbstractPresenter<Cost> {
	final String SINGLEITEM = "cost";
	final String MULTIITEM = "costs";
	
	public ArrayList<Cost> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public Cost tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public Cost createItemFromJSONObject(JSONObject jsonObject){
		Cost item = new Cost();
		try{
			item.setCostDesc(jsonObject.getString("costDesc"));
			item.setCostID(jsonObject.getInt("costID"));
			
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(Cost item){
		try{
			JSONObject json = new JSONObject();
			json.put("costDesc", item.getCostDesc());
			json.put("costID", item.getCostID());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public Cost getEmptyEntity(){
		Cost entity = new Cost();
		return entity;
	}
}
